package com.yz.vi.commons.helper;

import com.yz.vi.commons.exception.MSBizNormalException;
import com.yz.vi.commons.result.Result;

/**
 * @author: yutingting
 * @descrption: 结果返回工具类
 * @create: 2019/7/9 8:42
 */
public class ResultUtils {

    public static final String SUCCESS_CODE = "200";

    public static <T> Result buildSuccessResult(T data) {
        return new Result(true, null, data);
    }

    public static Result buildSuccessResult() {
        return new Result(true, null, null);
    }

    public static Result buildErrorResult(MSBizNormalException ex) {
        Result result = new Result();
        result.setSuccess(false);
        result.addError(ex.getErrorCode(), ex.getErrorMsg(), "", ex);
        return result;
    }

    public static Result buildErrorResult(String errorCode, String errorMessage) {
        Result result = new Result();
        result.setSuccess(false);
        result.addError(errorCode, errorMessage, "");
        return result;
    }
}
